import { Login } from '../index'
import { setToken, setSessionToken } from '@/utils/token'
import router from '@/router/index'

export async function login(data) {
    try {
        await Login.login(data);
        router.push('/home');
    } catch (error) {
        console.log(error);
    }
}

export async function oncelogin(data) {
    try {
        const response = await Login.login(data);
        const token = response.data.token;
        setSessionToken('token', token);
        router.push('/home');
    } catch (error) {
        console.log(error);
    }
}

export async function register(data) {
    try {
        await Login.register(data);
    } catch (error) {
        console.log(error);
    }
}

export async function logout() {
    try {
        await Login.logout();
    } catch (error) {
        console.log(error);
    }
}